package model.graphic.objects;

import controller.Constants;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Stroke;
import model.graphic.locations.FlexibleRelativeLocation;

/**
 *
 * @author Jelle, modified by Ben Willekens
 */
public class GHandleConnection extends GConnection {

    private GOutput output=null;
    private GInputPort input;
    private int modus = 0;

    public GHandleConnection() {
    }

    public GHandleConnection(GOutput triangle, GInputPort input) {
        super(new FlexibleRelativeLocation(triangle.getArrowBasePoint(), triangle.getX(), triangle.getY()), new FlexibleRelativeLocation(((RectangleAttachment) input).getGraphLocation(), 0, 0));
        this.output = triangle;
        this.input = input;
        modus = 1;
    }

    @Override
    public String getString() {
        return Constants.getHandleconnectionString();
    }

    @Override
    public void paint(Graphics2D g) {
        Stroke oldStroke = g.getStroke();
        Color oldColor = g.getColor();
        if (output!=null){
            target=new FlexibleRelativeLocation(output.getArrowBasePoint(),0,0);
        }
        source=new FlexibleRelativeLocation(((RectangleAttachment) input).getGraphLocation(), -5, 0);

        if (this.isVisible()) {
            line.setLine(target.getX()+GOutput.ARROW_DELTA, target.getY(), source.getX(), source.getY()+15/2);

            if (highlighted || selected) {
                g.setStroke(new BasicStroke(2.0f));
                g.setColor(Color.RED);
            } else {
                g.setStroke(new BasicStroke(1.0f));
                g.setColor(Color.BLACK);
            }
            if (modus == 1) {
                if (output.isVisible()) {
                    getLine().paint(g);//g.draw(getLine());
                }
            } 
        }
        g.setColor(oldColor);
        g.setStroke(oldStroke);
    }

    /**
     * @return the output
     */
    public GOutput getOutput() {
            return output;
    }

    /**
     * @param output the output to set
     */
    public void setOutput(GOutput output) {
        this.output = output;
    }

    /**
     * @param target the target to set
     */
    public void setInput(GInputPort input) {
        this.input = input;
    }

    /**
     * @return the target
     */
    public GInputPort getInput() {
        return input;
    }
}

